package com.linln.agent.notice;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.linln.common.constant.AdminConst;
import com.linln.modules.member.domain.MemberAgent;
import com.linln.modules.member.domain.MemberInfo;
import com.linln.modules.member.domain.Notice;
import com.linln.modules.member.service.NoticeService;

/**
 * @author hct
 * @date 2019/09/12
 */
@Controller
@RequestMapping("agent/notice")
public class AgentNoticeController {

	  @Autowired
	    private NoticeService noticeService;

	    /**
	     * 列表页面
	     */
	    @GetMapping("/index")
 	    public String index(Model model, Notice notice,HttpServletRequest request) {

	        // 创建匹配器，进行动态查询匹配
	        ExampleMatcher matcher = ExampleMatcher.matching();
	       // MemberInfo agent=(MemberInfo)request.getSession().getAttribute(AdminConst.AGENT_ROLE_NAME);
	        MemberAgent agent=(MemberAgent)request.getSession().getAttribute(AdminConst.AGENT_AREA_NAME); 
	        
	        notice.setArea(agent.getArea());
	        // 获取数据列表
	        Example<Notice> example = Example.of(notice, matcher);
	        Page<Notice> list = noticeService.getPageList(example);
	        // 封装数据
	        model.addAttribute("list", list.getContent());
	        model.addAttribute("page", list);
	        return "/agent/notice/index";
	    }

     
}